package ossFileinfo

import (
	"common/dao/model"
	"common/utils"
	"context"
	"github.com/jinzhu/copier"
	"time"

	"file/internal/svc"
	"file/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UploadFileInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUploadFileInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadFileInfoLogic {
	return &UploadFileInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UploadFileInfoLogic) UploadFileInfo(req *types.UploadInfoResponse) (resp *types.UploadInfoResp, err error) {
	// todo: add your logic here and delete this line
	var (
		file = model.SysFile{}
	)
	file.UUID = utils.GetUuid()
	err = copier.Copy(&file, req)
	if err != nil {
		return nil, err
	}
	t := time.Now()
	file.CreateTime = &t
	err = l.svcCtx.DB.Create(&file).Error
	if err != nil {
		return nil, err
	}
	return
}
